package com.example.readbook.UI.BaseUI;

import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.example.readbook.MyApp;
import com.example.readbook.Utils.UIUtils;

/**
 * ClassName: : ${type_name}
 * Description: ${todo}(这里用一句话描述这个类的作用)
 * Copyright  : Copyright (c) 2016
 * Author     : 小小码农
 * Date       : 2017/10/12 17:55
 */

public abstract class BaseStatusBarActivity extends BaseActivity{
    protected MyApp                application;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        application = (MyApp) getApplication();
        //        判断SDK版本是否大于等于19，大于就让他显示，小于就要隐藏，不然低版本会多出来一个
        //        背景为白色时造成遮挡状态栏数据.
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            setTranslucentStatus(true);
        } else {
            setTranslucentStatus(false);
        }
        UIUtils.setStatusBar(this, 1, 0);
        //        //亮色状态栏字体颜色为暗色
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            //        官方在Android6.0中提供了亮色状态栏模式，配置只需一行代码
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
        //        Logger.addLogAdapter(new AndroidLogAdapter());
    }


    /**
     * 布局view
     * @return
     */
    public abstract int getLayoutResID();

    /**
     * 初始化控件
     */
    public abstract void initView();

    /**
     * 初始化监听
     */
    public abstract void initListener();

    /**
     * 初始化数据
     */
    public abstract void initData();




    @TargetApi(19)
    private void setTranslucentStatus(boolean on) {
        Window win = getWindow();
        WindowManager.LayoutParams winParams = win.getAttributes();
        final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
        if (on) {
            winParams.flags |= bits;
        } else {
            winParams.flags &= ~bits;
        }
        win.setAttributes(winParams);
    }

    @Override
    protected void onPause() {
        super.onPause();
        if (loading.isShowing())
            loading.dismiss();
    }
}
